package dijjer.io.xfer.http.handlers;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import dijjer.io.xfer.http.HTTPResponse;
import dijjer.util.GIFEncoder;
import dijjer.util.logging.Logger;

public class GIFResponse extends HTTPResponse {

	public static final String VERSION = "$Id: GIFResponse.java 2 2008-03-21 14:33:03Z ian.clarke $";

	private final byte[] _gif;

	public GIFResponse(GIFEncoder gif, int code, String message)
	{
		super(code, message, "image/gif");
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		try {
			gif.write(out);
		} catch (IOException e) {
			Logger.error(e);
		}
		_gif = out.toByteArray();
	}

	protected long getContentLength()
	{
		return _gif.length;
	}

	protected void writeTo(OutputStream out) throws IOException
	{
		out.write(_gif);
	}
}
